Skip to content

fix: rival apply/#658#667

Merged
redjungi09 merged 2 commits into
developfrom
fix/rival-apply/#658
Apr 12, 2026
Merged

fix: rival apply/#658#667
redjungi09 merged 2 commits into
developfrom
fix/rival-apply/#658

Conversation

@hjbin-25

Copy link
Copy Markdown
Member

변경사항

  • 라이벌 동시 신청 시 레이스 컨디션으로 같은 유저 쌍 사이에 PENDING 레코드가 2개 생성되는 버그 수정
  • DB 레벨 방어: rivals 테이블에 uq_rivals_active_pair unique partial index 추가 (LEAST/GREATEST로 방향 정규화, PENDING/ACCEPTED 상태만 적용)
  • 기존 중복 데이터 정리: 마이그레이션(V32)에서 PENDING-PENDING 중복 및 ACCEPTED 상태임에도 남아있는 PENDING 레코드 제거
  • 라이벌 수락 시 반대 방향 미러 PENDING 레코드 자동 취소 (AcceptRivalService.cancelMirrorPendingIfExists)
  • ApplyRivalService에서 DB constraint 위반 시 DataIntegrityViolationExceptionAlreadyAppliedRivalException (500 → 409) 변환

관련 이슈

Closes #658

추가 컨텍스트

레이스 컨디션 발생 조건

PostgreSQL 기본 격리 수준(READ COMMITTED)에서 A→B, B→A 신청이 동시에 들어오면
existsActiveRivalBetween 체크가 두 트랜잭션 모두 통과해 중복 레코드가 생성됨.

방어 레이어
1차 (애플리케이션): existsActiveRivalBetween 체크 (기존)
↓ 레이스 컨디션으로 뚫릴 경우
2차 (DB): uq_rivals_active_pair 인덱스가 INSERT 거부
↓ 거부 시
3차 (예외 변환): DataIntegrityViolationException → AlreadyAppliedRivalException (409)

마이그레이션 주의사항

user_notices.rival_id의 FK가 ON DELETE SET NULL이므로 rivals 삭제 전 notices를 먼저 삭제 (orphan notice 방지). Step 1 → Step 2 → Step 3 순차 실행, 단일 트랜잭션으로 실패 시
전체 롤백.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a unique database constraint to prevent duplicate rival records and includes a migration script to clean up existing entries. It also adds error handling for integrity violations during the rival application process. The review feedback highlights that the manual mirror-record cleanup logic in the service and repository layers is now redundant due to the new database constraint and should be removed. Additionally, the reviewer pointed out that the GetMyRivalActingServiceTest class was improperly disabled by being commented out and must be restored.

@hjbin-25 hjbin-25 self-assigned this Apr 12, 2026
@hjbin-25 hjbin-25 added the bug 기능이 정상적으로 작동하지 않음 label Apr 12, 2026
@redjungi09 redjungi09 merged commit b86e753 into develop Apr 12, 2026
1 check passed
@hjbin-25 hjbin-25 deleted the fix/rival-apply/#658 branch April 12, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 기능이 정상적으로 작동하지 않음

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants